﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Dal;

public partial class Course_CourseTeamEdit : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDDL();
            BindTeamList();
        }
    }


    /// <summary>
    /// 绑定下拉列表
    /// </summary>
    private void BindDDL()
    {
        ddlCourseType.DataSource = CourseInfoBiz.GetCourseTypeList();
        ddlCourseType.DataTextField = "CourseTypeName";
        ddlCourseType.DataValueField = "CourseTypeID";
        ddlCourseType.DataBind();      
    }

    /// <summary>
    /// 绑定分组信息
    /// </summary>
    private void BindTeamList()
    {
        string str=Request.QueryString["TeamID"];

        if(str!=null)
        {
           int teamID = Convert.ToInt32(str);
           Proc_CourseTeam_SelectInfoResult team= CourseInfoBiz.GetCourseTeamInfo(teamID);
            if(team!=null)
            {
               txtTeamName.Text= team.TeamName;
               ddlCourseType.Text = Convert.ToString(team.CourseType);
               txtSort.Text = Convert.ToString(team.Sort);
               ddlStatus.Text = team.Status.ToString();
               txtMemo.Text = team.Memo;
            }
        }

    }

    /// <summary>
    /// 保存数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (txtTeamName.Text.Trim() == "")
        {
            lblWarn.Text = "请输入课程分组名称！";
            txtTeamName.Focus();
            return;
        }


        string Ssort =txtSort.Text.Trim();
        int resulter;
        bool f = Int32.TryParse(Ssort, out resulter);
        if (f)
        {
            lblWarn.Text = "";
        }
        else
        {
            lblWarn.Text = "请输入正确排序数字！";
            txtSort.Text = "0";
            txtSort.Focus();
            return;
        }

        string str=Request.QueryString["TeamID"];
        int teamID = Convert.ToInt32(str);
        string teamName = txtTeamName.Text.Trim();
        int sort = Convert.ToInt32(txtSort.Text.Trim());
        string memo = txtMemo.Text.Trim();
        int courseType=Convert.ToInt32(ddlCourseType.Text.Trim());
        int status = Convert.ToInt32(ddlStatus.Text.Trim());

        Proc_CourseTeam_SelectInfoResult team=new Proc_CourseTeam_SelectInfoResult()
        {
             TeamID  =teamID,   
             TeamName=teamName,
             CourseType=courseType,
             Sort=sort,
             Status = status,
             Memo=memo
        };

        //编辑分组信息
        if(team!=null)
        {
             if(str!=null)
             {
                 team.TeamID = Convert.ToInt32(str);
                 bool b = CourseInfoBiz.GetCourseTeamUpdate(teamID,teamName,courseType,sort,status,memo);
                 if (b)
                 {
                     lblWarn.Text = "课程分组编辑成功！";
                     lblWarn.ForeColor = System.Drawing.Color.Green;
                     btnOK.Enabled = false;
                 }
                 else
                 {

                     lblWarn.Text = "课程分组编辑失败！";
                     lblWarn.ForeColor = System.Drawing.Color.Red;

                 }

                 Response.Redirect("CourseTeamList.aspx");
             }

             else
             {
                 bool b = CourseInfoBiz.GetCourseTeamAdd(teamName, courseType, sort, status, memo);
                 if (b)
                 {
                     lblWarn.Text = "课程分组添加成功！";
                     lblWarn.ForeColor = System.Drawing.Color.Green;
                     btnOK.Enabled = false;
                 }
                 else
                 {

                     lblWarn.Text = "课程分组添加失败！";
                     lblWarn.ForeColor = System.Drawing.Color.Red;

                 }
                 Response.Redirect("CourseTeamList.aspx");

             }
        }

    }

    /// <summary>
    /// 返回
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("CourseTeamList.aspx");
    }

}